package com.gitee.wsl.base

import com.gitee.wsl.transform.format.DEFAULT_INT_RANGE_TO_STRING
import com.gitee.wsl.transform.format.HowIntRangeToString

interface IIntRange {
    operator fun contains(i: Int): Boolean;

    fun toString(how: HowIntRangeToString): String
}

data class FiniteRange(val start: Int, val end: Int) : IIntRange {
    constructor(v: Int) : this(v, v)

    override fun contains(i: Int): Boolean {
        return i in start..end
    }

    override fun toString(how: HowIntRangeToString): String {
        return if (start == end) how.intToString(start) else "(${how.intToString(start)}-${how.intToString(end)})"
    }

    override fun toString(): String {
        return toString(DEFAULT_INT_RANGE_TO_STRING)
    }
}

class InfiniteRange : IIntRange {
    override fun contains(i: Int): Boolean {
        return true
    }

    override fun toString(how: HowIntRangeToString): String {
        return how.infiniteToString()
    }

    override fun toString(): String {
        return toString(DEFAULT_INT_RANGE_TO_STRING)
    }
}

data class LeftInfiniteRange(val end: Int) : IIntRange {
    override fun contains(i: Int): Boolean {
        return i <= end
    }

    override fun toString(how: HowIntRangeToString): String {
        return "(${how.negativeInfiniteToString()}-${how.intToString(end)})"
    }

    override fun toString(): String {
        return toString(DEFAULT_INT_RANGE_TO_STRING)
    }
}

data class RightInfiniteRange(val start: Int) : IIntRange {
    override fun contains(i: Int): Boolean {
        return i >= start
    }

    override fun toString(how: HowIntRangeToString): String {
        return "(${how.intToString(start)}-${how.positiveInfiniteToString()})"
    }

    override fun toString(): String {
        return toString(DEFAULT_INT_RANGE_TO_STRING)
    }
}

class LightRegexException(message: String?) : RuntimeException(message)
